{% extends 'layout.html' %}
{% load static %}

{% block content %}
    <div class="container-fluid" style="margin-top: 20px;">

        <div class="col-md-12">
            <div class="panel panel-info mystyle-panel">
                <div class="panel-heading">
                    首页
                    {% csrf_token %}
                </div>
                <div class="panel-body">
                    欢迎登录！
                </div>
            </div>
        </div>
    </div>
{% endblock content %}

{% block js %}
    <script src="{% static 'js/ajax_setup.js' %}"></script>
    <script>
        $('.fa-trash-o').click(function () {
            swal({
                title: "你确定要删除吗？",
                text: "数据一旦删除，将无法恢复！",
                icon: "warning",
                buttons: true,
                dangerMode: true,
            })
                .then((willDelete) => {
                    if (willDelete) {
                        $.ajax({
                            url: $(this).attr('url'),
                            type: 'post',
                            success: (ret) => {
                                if (ret.status === 0) {
                                    swal("哇哦，数据删除成功！", {
                                        icon: "success",
                                    });
                                    $(this).parent().parent().parent().remove()
                                } else {
                                    swal(ret.msg)
                                }
                            },
                            error: function (ret) {
                                swal('error:' + ret)
                            }
                        });
                    } else {
                        swal("数据没有被删除！");
                    }
                });
        });
    </script>
{% endblock %}